<?php

require "../types.php";
require "../utility.php";

$conn = connect_mysql();

$user_id = getUserIdBySessionId($conn);

http_response_code(403);

if ($user_id !== null) {
    http_response_code(200);
    $query_str = "SELECT ID, address, isDefault FROM Addr WHERE userID = '$user_id';";
    $query = $conn->query($query_str);

    $addrs = [];
    while ($addr_data = $query->fetch_row()) {
        $addr = Addr::fromArray($addr_data);
        array_push($addrs, $addr);
    }

    $query->close();
    echo json_encode($addrs);
}

$conn->close();

?>